﻿using System;
using System.Collections.Generic;
using System.Text;

namespace CpuSimulator.Instructions
{
    /// <summary>
    /// SLLI(Shift Left Logical Immediate) 将rs1的值逻辑左移立即数中的值，并将结果写入rd
    /// 立即数只取低五位，因为32位的数据最大也就移动2的5次方=32位，相当于R类型指令中rs2的位置
    /// 立即数的高七位固定位0000000
    /// _________________________________________________________________________________________________________________________________________________
    /// |_________________立即数12位________________________|_________rs1,5位______|_Func3______|_________rd,5位______|_____OPCODE 7位____________|
    /// | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 09 | 08 | 07 | 06 | 05 | 04 | 03 | 02 | 01 | 00 |
    /// |                    0000000+低五位                                  |       rs1                     |    001          |        rd                      |            0010011                     |
    /// </summary>
    public class SLLI : Instruction
    {
        public override void Execute(Cpu cpuinfo)
        {
            var newVal = cpuinfo.Registers[this.Rs1].Value << this.Rs2; //立即数的低五位，相当于Rs2的位置
            cpuinfo.Registers[this.Rd].SetValue(newVal);
            cpuinfo.InvodeRegisterChange(this.Rd, newVal.ToString("X8"));
        }
    }
}
